<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['purs:cdd:add']"
        >新增</el-button>
      </el-col>
      
    </el-row>

    <el-table v-loading="loading" :data="cddList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="候选人编号" align="center" prop="cddId" />
      <el-table-column label="投标人名称" align="center" prop="supName" />
      <el-table-column label="供应商编号" align="center" prop="supCode" />
      <el-table-column label="最终报价" align="center" prop="finalQuote" />
      <el-table-column label="最终得分" align="center" prop="finalScore" />
      <el-table-column label="是否推荐" align="center" prop="recommended" />
      <el-table-column label="排名" align="center" prop="ranking" />
      <el-table-column label="是否中标" align="center" prop="winningBid" />
      <el-table-column label="项目编号" align="center" prop="bindCode" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['purs:cdd:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['purs:cdd:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改候选人列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="投标人名称" prop="supName">
          <el-input v-model="form.supName" placeholder="请输入投标人名称" />
        </el-form-item>
        <el-form-item label="供应商编号" prop="supCode">
          <el-input v-model="form.supCode" placeholder="请输入供应商编号" />
        </el-form-item>
        <el-form-item label="最终报价" prop="finalQuote">
          <el-input v-model="form.finalQuote" placeholder="请输入最终报价" />
        </el-form-item>
        <el-form-item label="最终得分" prop="finalScore">
          <el-input v-model="form.finalScore" placeholder="请输入最终得分" />
        </el-form-item>
        <el-form-item label="是否推荐" prop="recommended">
          <el-input v-model="form.recommended" placeholder="请输入是否推荐" />
        </el-form-item>
        <el-form-item label="排名" prop="ranking">
          <el-input v-model="form.ranking" placeholder="请输入排名" />
        </el-form-item>
        <el-form-item label="是否中标" prop="winningBid">
          <el-input v-model="form.winningBid" placeholder="请输入是否中标" />
        </el-form-item>
        <el-form-item label="项目编号" prop="bindCode">
          <el-input v-model="form.bindCode" placeholder="请输入项目编号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCdd, getCdd, delCdd, addCdd, updateCdd } from "@/api/purs/cdd";

export default {
  name: "Cdd",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 候选人列表表格数据
      cddList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询候选人列表列表 */
    getList() {
      this.loading = true;
      listCdd(this.queryParams).then(response => {
        this.cddList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        cddId: null,
        supName: null,
        supCode: null,
        finalQuote: null,
        finalScore: null,
        recommended: null,
        ranking: null,
        winningBid: null,
        bindCode: null
      };
      this.resetForm("form");
    },
   
  
    
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加候选人列表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const cddId = row.cddId || this.ids
      getCdd(cddId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改候选人列表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.cddId != null) {
            updateCdd(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCdd(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const cddIds = row.cddId || this.ids;
      this.$modal.confirm('是否确认删除候选人列表编号为"' + cddIds + '"的数据项？').then(function() {
        return delCdd(cddIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
   
  }
};
</script>
